<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Linkscard extends Model
{
    protected $table = 'links_card';
    protected $primaryKey = 'id';

    public static function creatLinksCard($links_id,$title,$describe,$logo,$type,$link_type)
    {
        return self::insert(["links_id"=>$links_id,"type"=>$type,"title"=>$title,"describe"=>$describe,"logo"=>$logo,"link_type"=>$link_type,"created_at"=>time()]);
    }

    public static function updateLinksCard($links_id,$title,$describe,$logo,$type,$link_type)
    {
        return self::where("links_id",$links_id)->where("type",$type)->update(["title"=>$title,"type"=>$type,"describe"=>$describe,"logo"=>$logo,"link_type"=>$link_type]);
    }

    public static function getLinksCard($links_id,$type)
    {
        return self::select("title","describe","logo","type")->where('links_id', $links_id)->where('type', $type)->first();
    }

    public static function linkCardDetial($links_id)
    {
        return self::where('links_id', $links_id)->first();
    }

    public static function linkCardDisableUpdate($links_id,$disable)
    {
        return self::where('links_id', $links_id)->update(["disable"=>$disable]);
    }

    public static function adminLinksCard($title,$describe,$links_id)
    {
        $query = self::query();
        if (!empty($links_id)) $query->where("links_id",$links_id);
        if (!empty($title)) $query->where("title","like","%".$title."%");
        if (!empty($describe)) $query->where("describe","like","%".$describe."%");
        return $query->orderBy("id","DESC")->paginate(25);
    }
}
